﻿using CMS.DataAccess;
using CMS.Model;
using CMS.Utils;
using Microsoft.Data.Sqlite;

namespace CMS.AOP
{
    public class AfterCourseSaveChangeInfoAction : IAfterSaveAction<CourseModel>
    {
        public void DoAction(CourseModel data)
        {
            var isntance = ServiceLoader.GetService<DbInstance>();
            var p1 = new SqliteParameter("@p1",data.Color);
            var p2 = new SqliteParameter("@p2", data.Pk);
            var p3 = new SqliteParameter("@p3", data.Optional);
            var p4 = new SqliteParameter("@p4", data.GroupClass);
            try
            {
                isntance.ExeSql("update schedule set color = @p1,optional=@p3,groupclass=@p4 where del = 'N' and course = @p2", p1, p2, p3, p4);
                isntance.ExeSql("update scheduletemplate set color = @p1,optional=@p3,groupclass=@p4 where del = 'N' and course = @p2", p1, p2, p3, p4);
            }

            catch (Exception ex)
            { 
                //静默更新，更新不了也不纠结
            }
        }
    }
}
